@echo off
del *.bak /s
del *.ddk /s
del *.edk /s
del *.lst /s
del *.lnp /s
del *.mpf /s
del *.mpj /s
del *.obj /s
del *.omf /s
del *.plg /s
del *.rpt /s
del *.tmp /s
del *.__i /s
del *.crf /s
del *.o /s
del *.d /s
del *.axf /s
del *.tra /s
del *.dep /s           
del JLinkLog.txt /s
del build_log.txt /s

del *.iex /s
del *.htm /s
del *.map /s

::set UV="C:\Keil_v526\UV4\UV4.exe"
set UV="D:\Program Files\Keil_v5\UV4\UV4.exe"

for /f "usebackq delims=" %%j in (`dir /s /b %cd%.\*.uvprojx`) do (
if exist %%j (
set UV_PRO_PATH="%%j"))


echo ---------------------------------------------------------------
echo Author:YUJQ
echo Init building ...
echo >build_log.txt
::%UV% -j0 -b %UV_PRO_PATH% -l %cd%\build_log.txt
%UV% -j0 -b %UV_PRO_PATH% -l build_log.txt

for /f "delims=[" %%i in (build_log.txt) do echo %%i

::echo exit %errorlevel%
echo %errorlevel%

if %errorlevel% LEQ 1 goto ok
if %errorlevel% NEQ 0 goto err

:ok
::HexView\hexview.exe Output\Q2026_MCU_APP.hex /S /FR:0x6FC00,4 /FP:736A293E /XI:16 -o Output\Q2026_MCU_APP_PP_TMP.hex
::HexView\hexview.exe Output\Q2026_MCU_APP_PP_TMP.hex /S /FR:0x6FE00,4 /FP:736A293E /XI:16 -o Output\Q2026_MCU_APP_PP.hex
::DEL Output\Q2026_MCU_APP_PP_TMP.hex
set /a ret=0
echo exit %ret%
exit /b %ret%
goto done

:err
set /a ret=1
echo exit %ret%
exit /b %ret%
::echo exit %errorlevel%
::exit /b %errorlevel%
goto done

:done

